using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ServiceModel.Channels;


namespace SlasheneFramework.WCF
{
	public class ReplyToChannel : ProxyOutputChannel
	{
		readonly Uri _ReplyAddress;
		public ReplyToChannel(Uri replyAddress, IOutputChannel inner)
			: base(inner)
		{
			_ReplyAddress = replyAddress;
		}
		public override void Send(Message message)
		{
			ApplyReplyTo(message);
			base.Send(message);
		}
		public override void Send(Message message, TimeSpan timeout)
		{
			ApplyReplyTo(message);

			base.Send(message, timeout);
		}

		void ApplyReplyTo(Message message)
		{
			message.Headers.MessageId = new System.Xml.UniqueId();
			message.Headers.From = new System.ServiceModel.EndpointAddress(_ReplyAddress);
			message.Headers.ReplyTo = new System.ServiceModel.EndpointAddress(_ReplyAddress);
		}
	}
}
